package main

type Difference struct {
	diff []int
}

func NewDifference(nums []int) *Difference {
	diff := &Difference{}
	if n := len(nums); n > 0 {
		diff.diff = make([]int, n)
		diff.diff[0] = nums[0]

		for i := 1; i < n; i++ {
			diff.diff[i] = nums[i] - nums[i-1]
		}
	}

	return diff
}

func (d *Difference) Increment(i, j, val int) {
	d.diff[i] += val
	if j+1 < len(d.diff) {
		d.diff[j+1] -= val
	}
}

func (d *Difference) Result() []int {
	res := make([]int, len(d.diff))
	res[0] = d.diff[0]
	for i := 1; i < len(d.diff); i++ {
		res[i] = res[i-1] + d.diff[i]
	}

	return res
}
